//
//  MyLikeController.m
//  GuShiNews
//
//  Created by huachun on 2019/8/28.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "MyLikeController.h"
#import "HiLikeCell.h"
#import "UserHomeController.h"
#import "SameCarViewModel.h"

@interface MyLikeController ()<SameCarHDelegate>

@end

@implementation MyLikeController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    if (_Here_type == 0) {
        self.navigationItem.title = @"我的粉丝";
    }else if (_Here_type == 1){
        self.navigationItem.title = @"我关注的";
    }else if (_Here_type == 2){
        self.navigationItem.title = @"黑名单";
    }
    
    self.Data_array = [NSMutableArray new];
    
    [self.view addSubview:self.TableView];
    self.TableView.separatorInset      = UIEdgeInsetsMake(0, 15, 0, 0);
    self.TableView.separatorStyle      = UITableViewCellSeparatorStyleSingleLineEtched;
    self.TableView.backgroundColor = [JonesClass stringTOColor:@"#fbfbfb"];
    self.TableView.separatorColor  = [JonesClass stringTOColor:@"#e9e9e9"];
    MJHiCarHeader *header           = [MJHiCarHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadnew)];
    header.automaticallyChangeAlpha    = YES;
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.hidden           = YES;
    self.TableView.mj_header          = header;
    self.TableView.mj_header.automaticallyChangeAlpha = YES;
    self.TableView.decelerationRate = UIScrollViewDecelerationRateFast;
    [self.TableView.mj_header beginRefreshing];
}

-(void)viewDidDisappear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] postNotificationName:CHONGXINTIXINGCOUNT object:nil];
    [super viewDidDisappear:animated];
}

- (void)loadnew{
    NSMutableDictionary *lindic = [NSMutableDictionary new];
    UserModel *linusermo = [UserModel info];
    [lindic setValue:linusermo.userid forKey:@"userid"];
    [lindic setValue:[NSString stringWithFormat:@"%li",_Here_type] forKey:@"type"];
    
    SameCarViewModel *viewmodel = [[SameCarViewModel alloc] init:lindic];
    viewmodel.delegate=self;
}


- (void)Succes:(int)value array:(NSMutableArray *)array page:(nonnull NSString *)page{
    if (value==1) {
        if ([page isEqualToString:@"0"]) {
            [self.Data_array removeAllObjects];
        }
        [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [self.Data_array addObject:obj];
        }];
        [self.TableView reloadData];
    }
    [self endloading];
}

- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state {
    NSString *text = @"暂无数据!";
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    [attStr addAttribute:NSFontAttributeName
                   value:[UIFont systemFontOfSize:14.0]
                   range:NSMakeRange(0, text.length)];
    [attStr addAttribute:NSForegroundColorAttributeName
                   value:[JonesClass stringTOColor:@"#cccccc"]
                   range:NSMakeRange(0, text.length)];
    return attStr;
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.Data_array.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HiLikeCell *cell = [HiLikeCell cellForTableView:tableView cellForRowAtIndexPath:indexPath];
    cell.Model = [self.Data_array objectAtIndex:indexPath.row];
//    if (_Here_type != 1){
//        cell.new_line.hidden = YES;
//    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UserHomeController *uwerdfsf = [UserHomeController new];
    uwerdfsf.hidesBottomBarWhenPushed = YES;
    uwerdfsf.Model = [self.Data_array objectAtIndex:indexPath.row];;
    [self.navigationController pushViewController:uwerdfsf animated:YES];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
